package com.Endurancer.manager.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.Endurancer.manager.domain.vo.ThemesVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.Endurancer.common.annotation.Log;
import com.Endurancer.common.core.controller.BaseController;
import com.Endurancer.common.core.domain.AjaxResult;
import com.Endurancer.common.enums.BusinessType;
import com.Endurancer.manager.domain.BlogThemes;
import com.Endurancer.manager.service.IBlogThemesService;
import com.Endurancer.common.utils.poi.ExcelUtil;
import com.Endurancer.common.core.page.TableDataInfo;

/**
 * 博客主题Controller
 *
 * @author Endurancer
 * @date 2025-02-02
 */
@RestController
@RequestMapping("/manager/themes")
public class BlogThemesController extends BaseController
{
    @Autowired
    private IBlogThemesService blogThemesService;

    /**
     * 查询最热主题列表
     */
    @GetMapping("/selectPopularThemes")
    public AjaxResult selectPopularThemes()
    {

        List<ThemesVo> list = blogThemesService.selectPopularThemes();
        return success(list);
    }

    /**
     * 查询博客主题列表
     */
//    @PreAuthorize("@ss.hasPermi('manager:themes:list')")
    @GetMapping("/list")
    public TableDataInfo list(BlogThemes blogThemes)
    {
        startPage();
        List<BlogThemes> list = blogThemesService.selectBlogThemesList(blogThemes);
        return getDataTable(list);
    }

    /**
     * 导出博客主题列表
     */
    @PreAuthorize("@ss.hasPermi('manager:themes:export')")
    @Log(title = "博客主题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlogThemes blogThemes)
    {
        List<BlogThemes> list = blogThemesService.selectBlogThemesList(blogThemes);
        ExcelUtil<BlogThemes> util = new ExcelUtil<BlogThemes>(BlogThemes.class);
        util.exportExcel(response, list, "博客主题数据");
    }

    /**
     * 获取博客主题详细信息
     */
    @PreAuthorize("@ss.hasPermi('manager:themes:query')")
    @GetMapping(value = "/{themeId}")
    public AjaxResult getInfo(@PathVariable("themeId") Long themeId)
    {
        return success(blogThemesService.selectBlogThemesByThemeId(themeId));
    }

    /**
     * 新增博客主题
     */
    @PreAuthorize("@ss.hasPermi('manager:themes:add')")
    @Log(title = "博客主题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlogThemes blogThemes)
    {
        return toAjax(blogThemesService.insertBlogThemes(blogThemes));
    }

    /**
     * 修改博客主题
     */
    @PreAuthorize("@ss.hasPermi('manager:themes:edit')")
    @Log(title = "博客主题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlogThemes blogThemes)
    {
        return toAjax(blogThemesService.updateBlogThemes(blogThemes));
    }

    /**
     * 删除博客主题
     */
    @PreAuthorize("@ss.hasPermi('manager:themes:remove')")
    @Log(title = "博客主题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{themeIds}")
    public AjaxResult remove(@PathVariable Long[] themeIds)
    {
        return toAjax(blogThemesService.deleteBlogThemesByThemeIds(themeIds));
    }
}
